﻿using FluentValidation;
using SXICE.Core.Models.Search;

namespace SXICE.Service.Validators
{
    /// <summary>
    /// 记录搜索验证器
    /// </summary>
    public class RecordSearchValidator : AbstractValidator<RecordSearchModel>
    {
        public RecordSearchValidator()
        {
            RuleFor(c => c.Name).MaximumLength(20).WithMessage("姓名长度不能超过20位");
            RuleFor(c => c.IDNumber).MaximumLength(18).WithMessage("身份证号长度不能超过18位");
            RuleFor(c => c.StartDate).Must((record, date) =>
            {
                if (!record.EndDate.HasValue || !date.HasValue)
                    return true;
                return record.EndDate.Value.Date >= date.Value.Date;
            }).WithMessage("开始日期不能大于结束日期");
        }
    }
}
